package com.ruicheng.iam.controller;

import com.ruicheng.iam.dto.ProjectInfoDTO;
import com.ruicheng.iam.dto.ProjectSearchDTO;
import com.ruicheng.iam.entity.ProjectInfo;
import com.ruicheng.iam.service.IProjectInfoService;
import com.ruicheng.iam.util.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目信息控制层
 * @author huang guang yue
 * @version v1.0.0
 * @date 2020 2020/11/25 11:34
 */
@RestController
@RequestMapping("/project")
@Api(tags = "项目控制器")
public class ProjectInfoController {

    @Resource
    private IProjectInfoService projectInfoService;

    /**
     * 添加项目
     * @param dto dto
     * @return com.ruicheng.iam.util.RestResult
     */
    @ApiOperation("添加项目")
    @PostMapping("/")
    @ApiResponses({
            @ApiResponse(code = 0, message = "添加成功")
    })
    public RestResult<Object> insertProject(@RequestBody @Valid ProjectInfoDTO dto){
        return projectInfoService.insertSelective(dto);
    }

    /**
     * 项目列表/搜索项目
     * @param dto 搜索实体
     * @return com.ruicheng.iam.util.RestResult
     */
    @ApiOperation("项目列表/搜索项目")
    @GetMapping("/")
    @ApiResponses({
            @ApiResponse(code = 0, message = "请求成功")
    })
    public RestResult<List<ProjectInfo>> searchProject(ProjectSearchDTO dto){
        return projectInfoService.searchProject(dto);
    }
}
